#include "sem.hpp"

void *Producer(void *arg)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(arg);
    while (1)
    {
        int number = rand() % 10;
        rq->Push(number);
        std::cout << "push success:" << number << std::endl;
        sleep(1);
    }
    return nullptr;
}
void *Consumer(void *arg)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(arg);
    while (1)
    {
        int p;
        rq->Pop(&p);
        std::cout << "pop success:" << p << std::endl;
        sleep(1);
    }
    return nullptr;
}
int main()
{
    srand(time(0) ^ getpid());
    pthread_t pro, con;
    RingQueue<int> *rq = new RingQueue<int>();
    pthread_create(&pro, nullptr, Producer, rq);
    pthread_create(&con, nullptr, Consumer, rq);

    pthread_join(pro, nullptr);
    pthread_join(con, nullptr);
    delete rq;
}